from pydantic import BaseModel, field_serializer, ConfigDict, Field
from datetime import datetime
from typing import Optional, Dict, Any
import json


class MedicalCaseBase(BaseModel):
  shop_id: str = Field(..., description="店铺ID")
  description: Optional[str] = Field(None, description="病例描述")
  patient_name: Optional[str] = Field(None, description="患者姓名")
  diagnosis: Optional[str] = Field(None, description="诊断结果")
  treatment_plan: Optional[str] = Field(None, description="治疗方案")

  class Config:
      from_attributes = True


class MedicalCaseCreate(MedicalCaseBase):
  case_images: str = Field(..., description="病例图片路径")
  patient_id: str = Field(None, description="用户id")
  status: Optional[str] = Field(default=1, description="状态")
  doctor_id: Optional[str] = Field(None, description="医生ID")
  doctor_name: Optional[str] = Field('', description="医生姓名")
  

  class Config:
      from_attributes = True
  
class MedicalCaseUpdate(BaseModel):
  id: str = Field(..., description="id")
  description: Optional[str] = Field(None, description="病例描述")
  patient_name: Optional[str] = Field(None, description="患者姓名")
  case_images: Optional[str] = Field(None, description="病例图片路径")
  diagnosis: Optional[str] = Field(None, description="诊断结果")
  treatment_plan: Optional[str] = Field(None, description="治疗方案")
  status: Optional[int] = Field(None, description="状态")
  doctor_id: Optional[str] = Field(None, description="医生ID")
  doctor_name: Optional[str] = Field(None, description="医生姓名")
  
  class Config:
    from_attributes = True

class ItemMedicalCase(MedicalCaseBase):
  id: str = Field(..., description="id")
  case_images: Optional[str] = Field(..., description="病例图片路径")
  patient_id: Optional[str] = Field(None, description="用户id")  # 确保包含这些字段
  doctor_id: Optional[str] = Field(None, description="医生ID")
  doctor_name: Optional[str] = Field('', description="医生姓名")
  create_time: Optional[datetime] = None
  update_time: Optional[datetime] = None
  deleted_at: Optional[datetime] = None
  status: Optional[int] = None
  
  @field_serializer('id')
  def serialize_id(self, id: int, _info):
    return str(id)  # 将 int 转换为 str
  
  class Config:
    from_attributes = True

class ListMedicalCase(BaseModel):
  shop_id: str = Field(..., description="店铺ID")
  patient_id: str = Field(..., description="用户id")
  create_time: Optional[datetime] = None
  pageIndex: int = Field(1, ge=1, description="页码")
  pageSize: int = Field(10, ge=1, le=100, description="每页数量")

  class Config:
    from_attributes = True


class FindMedicalCase(BaseModel):
  id: str = Field(..., description="id")

  class Config:
    from_attributes = True